Skip to content

feat: Add template config methods to AI SDK#184

Open
mattrmc1 wants to merge 2 commits into
mainfrom
mmccarthy/AIC-2854/java-enable-raw-prompt
Open

feat: Add template config methods to AI SDK#184
mattrmc1 wants to merge 2 commits into
mainfrom
mmccarthy/AIC-2854/java-enable-raw-prompt

Conversation

@mattrmc1

@mattrmc1 mattrmc1 commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds completionConfigTemplate, agentConfigTemplate, and judgeConfigTemplate to LDAIClient. These methods return the same config types as their non-template counterparts but skip Mustache interpolation, preserving {{variable}} and {{ldctx.key}} placeholders verbatim. Useful for displaying prompt previews, storing templates for later rendering, or auditing prompt content without variable substitution.

Template methods on LDAIClient

AICompletionConfig completionConfigTemplate(String key, LDContext context,
    AICompletionConfigDefault defaultValue);

AIAgentConfig agentConfigTemplate(String key, LDContext context,
    AIAgentConfigDefault defaultValue);

AIJudgeConfig judgeConfigTemplate(String key, LDContext context,
    AIJudgeConfigDefault defaultValue);

Each template method fires a -template suffixed usage event ($ld:ai:usage:completion-config-template, $ld:ai:usage:agent-config-template, $ld:ai:usage:judge-config-template) and does not fire the standard usage event. The variables parameter is omitted since interpolation is skipped.

LDAIClientImpl changes

The private evaluate, buildConfig, and buildConfigFromDefault methods accept a new boolean interpolate parameter. When false, interpolateMessages() / interpolate() calls are skipped and messages/instructions are passed through as-is from the parsed flag value or caller-supplied default. All existing call sites pass true — behavior is unchanged.

// Standard path
public AICompletionConfig completionConfig(String key, LDContext context, ...) {
    client.trackMetric(TRACK_USAGE_COMPLETION_CONFIG, context, LDValue.of(key), 1);
    return (AICompletionConfig) evaluate(key, context, effectiveDefault, Mode.COMPLETION, variables, true);
}

// Template path
public AICompletionConfig completionConfigTemplate(String key, LDContext context, ...) {
    client.trackMetric(TRACK_USAGE_COMPLETION_CONFIG_TEMPLATE, context, LDValue.of(key), 1);
    return (AICompletionConfig) evaluate(key, context, effectiveDefault, Mode.COMPLETION, null, false);
}

Migration

None required. LDAIClient gains three new members — this is additive only. Existing consumers that call the SDK through the concrete LDAIClientImpl class are unaffected. Consumers that implement LDAIClient in test doubles will need to add stub implementations for the three new methods.

Test plan

  • ./gradlew :lib:sdk:server-ai:test passes
  • completionConfigTemplateFiresTemplateUsageEvent — verifies the correct -template tracking event is emitted
  • completionConfigTemplatePreservesPlaceholders{{name}} survives in message content
  • completionConfigTemplateDoesNotInterpolateLdctx{{ldctx.key}} is not substituted with the context key
  • completionConfigTemplateNullDefaultYieldsDisabled — absent flag with null default returns disabled config
  • completionConfigTemplateHasTrackercreateTracker() returns non-null
  • agentConfigTemplate* — same five scenarios for agent configs (instructions rather than messages)
  • judgeConfigTemplate* — same five scenarios for judge configs

Note

Low Risk
Additive API and a guarded code path; existing consumers keep the same interpolation behavior unless they opt into the new template methods.

Overview
Adds completionConfigTemplate, agentConfigTemplate, and judgeConfigTemplate on LDAIClient so callers can fetch evaluated AI configs with Mustache placeholders ({{variable}}, {{ldctx.*}}) left verbatim—for previews, storage, or auditing—without a variables argument.

LDAIClientImpl threads a new interpolate flag through evaluate / buildConfig / buildConfigFromDefault; existing retrieval paths still pass true, so interpolated behavior is unchanged. Template paths pass false and emit separate usage metrics ($ld:ai:usage:*-config-template) instead of the standard config usage events.

Tests cover template tracking, placeholder and ldctx non-substitution, null-default disabled semantics, and non-null trackers for all three config kinds.

Reviewed by Cursor Bugbot for commit 8da0d6b. Bugbot is set up for automated code reviews on this repo. Configure here.

@mattrmc1 mattrmc1 marked this pull request as ready for review June 29, 2026 22:57
@mattrmc1 mattrmc1 requested a review from a team as a code owner June 29, 2026 22:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant